<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--仓库查询数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="订单号" prop="orderNo" label-width="90px">
            <el-input
              v-model="queryParams.orderNo"
              placeholder="请输入订单号"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订单名称" prop="orderName" label-width="90px">
            <el-input
              v-model="queryParams.orderName"
              placeholder="请输入订单名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="供应商名称" prop="keyword" label-width="100px">
            <el-input
              v-model="queryParams.keyword"
              placeholder="请输入订单名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="queryParams.orderStatus"
              placeholder="状态"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="dict in dict.type.wms_purchase_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['wms:purchase:add']"
            >新增</el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loading" :data="dataList" :fit="true" :highlight-current-row="true" :cell-style="cellInfo">
          <el-table-column label="订单号" align="center" key="orderNo" prop="orderNo" width="160"/>
          <el-table-column label="订单名称" align="center" key="orderName" prop="orderName"/>
          <el-table-column label="订单总额(元)" align="center" key="orderAmount" prop="orderAmount"/>
          <el-table-column label="供应商编号" align="center" key="supplierCode" prop="supplierCode"/>
          <el-table-column label="供应商名称" align="center" key="supplierName" prop="supplierName"/>
          <el-table-column label="供应商联系人" align="center" key="userName" prop="userName" width="160"/>
          <el-table-column label="联系电话" align="center" key="userTel" prop="userTel" width="160"/>
          <el-table-column label="是否退货" align="center" key="isReturn">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isReturn"/>
            </template>
          </el-table-column>
          <el-table-column label="退货金额(元)" align="center" key="returnAmount" prop="returnAmount"/>
          <el-table-column label="订单净额(元)" align="center">
            <template slot-scope="scope">
              {{scope.row.orderAmount - scope.row.returnAmount}}
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" key="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.wms_purchase_status" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" key="createBy" prop="createBy"/>
          <el-table-column label="创建时间" align="center" prop="createDate" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createDate) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            fixed="right"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                v-hasPermi="['wms:unitConvert:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-hasPermi="['wms:unitConvert:remove']"
                @click="handleDelete(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加或修改对话框 -->
  </div>
</template>

<script>
import { findAllList,delObj } from "@/api/wms/purchase";

export default {
  name: "PurchaseIndex",
  dicts: ['wms_purchase_status','sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据列表
      dataList: [],
      // 日期范围
      dateRange: [],
      cellInfo: {
        width: '160px'
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: undefined,
        orderName: undefined,
        orderStatus: undefined,
        keyword: undefined,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      findAllList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd(){
      this.$router.push("/purchase/create");
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除订单为"' + row.orderName + '"的数据项？').then(function() {
        return delObj(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
